<?php include "templates/include/header.php" ?>

      <div id="adminHeader">
        <h2>Administration des R&eacute;sultats</h2>
        <p>Vous etes connect&eacute; en tant que <b><?php echo htmlspecialchars( $_SESSION['username']) ?></b>. <a href="admin.php?action=logout"?>Se D&eacute;connecter</a></p>
      </div>

      <h1><?php echo htmlspecialchars( $results['pageTitle'] )?></h1>

      <form action="admin.php?action=<?php echo $results['formAction']?>" method="post">
        <input type="hidden" name="resultId" value="<?php echo $results['edit']->id ?>"/>

<?php if ( isset( $results['errorMessage'] ) ) { ?>
        <div class="errorMessage"><?php echo $results['errorMessage'] ?></div>
<?php } ?>

<?php 
  $data = Event::getList();
?>
        <table>
          <tr>
            <td>
              <label for="home_team">Equipe:</label>
              <input id="home_team" name="home_team" placeholder="Nom de l'&eacute;quipe" maxlength="255" value="<?php if ( isset( $results['edit']->home_team ) ) echo htmlspecialchars( $results['edit']->home_team )?>"/>
            </td>
            <td>
              <label for="home_score">Score:</label>
              <input id="home_score" name="home_score" placeholder="Score de l'&eacute;quipe" maxlength="10" width="20px" value="<?php if ( isset( $results['edit']->home_score ) ) echo htmlspecialchars( $results['edit']->home_score )?>"/>
            </td>
            <td>
              <label for="away_score">Score des visiteurs:</label>
              <input id="away_score" name="away_score" placeholder="Score des visiteurs" maxlength="10" width="20px" value="<?php if ( isset( $results['edit']->away_score ) ) echo htmlspecialchars( $results['edit']->away_score )?>"/>
            </td>
            <td>
              <label for="away_team">Visiteurs:</label>
              <input id="away_team" name="away_team" placeholder="Nom des visiteurs" maxlength="255" value="<?php if ( isset( $results['edit']->away_team ) ) echo htmlspecialchars( $results['edit']->away_team )?>"/>
            </td>
          </tr>
          <tr>
            <td>
              <label for="event_id">Evenement:</label>
              <select id="event_id" name="event_id">
                <?php
                  foreach( $data['results'] as $event ) {
                    echo( '<option value="' . $event->id . '"');
                    if( isset( $results['edit']->id ) ) {
                      if( $results['edit']->event_id == $event->id ) {
                        echo( ' selected="yes"' );
                      }
                    } elseif ( isset( $_GET['event'] ) ) {
                      if( $_GET['season'] == $event->id ) {
                        echo( ' selected="yes"' );
                      }
                    }
                    echo(' >' . $event->title . '</option>');
                  }
                ?>
              </select>
            </td>
          </tr>
        </table>
      <div class="buttons">
          <input type="submit" name="saveChanges" value="Enregister" />
          <input type="submit" formnovalidate name="cancel" value="Annuler" />
      </div>
    </form>

<?php if ( $results['edit']->id ) { ?>
      <p><a href="admin.php?action=deleteResult&amp;resultId=<?php echo $results['edit']->id ?>" onclick="return confirm('Supprimer cet element ?')">Supprimer cet Element</a></p>
<?php } ?>

<?php include "templates/include/footer.php" ?>
